package uz.rt.utils;

import junit.framework.TestCase;
import uz.rt.units.Angle;
import uz.rt.units.Length;

public class VoxelTest extends TestCase
{
    Voxel<Integer, Double, Double> voxel = null;
    Voxel<Length, Length, Angle> voxelAngle = null;

    public VoxelTest()
    {
        super();
        voxel = new Voxel<Integer, Double, Double>();
        Coordinate<Integer> center = new Coordinate<Integer>();
        center.add(0);
        center.add(1);
        center.add(2);
        Dimension<Double> dimension = new Dimension<Double>();
        dimension.add(1.3);
        dimension.add(4.5);
        dimension.add(7.1);
        try
        {
            voxel.setCenter(center);
            voxel.setDimensions(dimension);
            voxel.setValue(100.79);
        }
        catch (Exception e)
        {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

        voxelAngle = new Voxel<Length, Length, Angle>();
        Coordinate<Length> acenter = new Coordinate<Length>();
        acenter.add(new Length(5, Length.Unit.cm));
        acenter.add(new Length(3, Length.Unit.mm));
        acenter.add(new Length(6, Length.Unit.cm));
        Dimension<Length> adim = new Dimension<Length>();
        adim.add(new Length(10, Length.Unit.cm));
        adim.add(new Length(25, Length.Unit.cm));
        adim.add(new Length(1, Length.Unit.mm));
        try
        {
            voxelAngle.setCenter(acenter);
            voxelAngle.setDimensions(adim);
        }
        catch (Exception e)
        {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        voxelAngle.setValue(new Angle(10, -180, 180, Angle.Unit.degree));
    }

    public void testEquals() throws Exception
    {
        Voxel voxel2 = new Voxel<Integer, Double, Double>();
        Coordinate<Integer> center = new Coordinate<Integer>();
        center.add(0);
        center.add(1);
        center.add(3);
        Dimension<Double> dimension = new Dimension<Double>();
        dimension.add(1.3);
        dimension.add(4.5);
        dimension.add(7.1);
        voxel2.setCenter(center);
        voxel2.setDimensions(dimension);
        voxel2.setValue(100.79);
        if (voxel.equals(voxel2))
        {
            System.out.println("Voxels should be different instead of equal");
            assertEquals(false, true);
        }
        if (voxel.compareTo(voxel2) == 0)
        {
            System.out.println("Voxels should be different instead of equal");
            assertEquals(false, true);
        }
        center.edit(2, 2);
        voxel2.setCenter(center);
        if (!voxel.equals(voxel2))
        {
            System.out.println("Voxels should be equal instead of different");
            assertEquals(true, false);
        }
        if (voxel.compareTo(voxel2) != 0)
        {
            System.out.println("Voxels should be equal instead of different");
            assertEquals(false, true);
        }
    }

    public void testToString() throws Exception
    {
        System.out.println(voxel.toString());
        System.out.println(voxelAngle.toString());
        voxelAngle.getValue().scale(Angle.Unit.radian);
        System.out.println(voxelAngle.toString());
        voxelAngle.getValue().scale(Angle.Unit.degree);
        System.out.println(voxelAngle.toString());
    }
}
